﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace WindowsGame1
{
    class Emitter : BaseObject
    {
        public Particle m_PartType;
        public float m_fRadius;
        public float m_fFrequency;
        public float m_fTimer;


        public Emitter(float fRadius, float fFrequency, Particle PartType)
        {
            m_fRadius = fRadius;
            m_fFrequency = fFrequency;
            m_PartType = PartType;
            m_fTimer = fFrequency;
            m_Texture = GlobalContentManager.Instance.Texture("Glow");
        }

        public override void Update(float deltaT, KeyboardState LastKeyState)
        {
            for (int i=1; i<deltaT/m_fTimer; i++)
            {
                Particle tempPart = new Particle(m_PartType);
                tempPart.m_Position = new Vector2(m_Position.X + GlobalContentManager.Instance.RandomFloat(-m_fRadius, m_fRadius),
                                                  m_Position.Y + GlobalContentManager.Instance.RandomFloat(-m_fRadius, m_fRadius));
                tempPart.m_fLife = GlobalContentManager.Instance.RandomFloat(2.0f, 30.0f);
                tempPart.m_Velocity = new Vector2(GlobalContentManager.Instance.RandomFloat(-1.0f, 1.0f), GlobalContentManager.Instance.RandomFloat(-1.0f, 1.0f));
                tempPart.m_bAdditive = true;
                ObjectManager.Instance.m_ObjectList.Add(tempPart);
            }
            m_fTimer -= deltaT;
            if (m_fTimer <= 0.0f)
            {
                m_fTimer = m_fFrequency;
            }
        }

        public override void Render(SpriteBatch spriteBatch, Camera cam)
        {
            
        }

        public override void CollisionResponse(BaseObject other)
        {
            
        }
    }
}
